<template>
  <a-modal
    :visible.sync="visible"
    @cancel="cancel"
    @ok="ok"
    class="large-modal"
  >
    <searchData :search-data="searchArr" @search="search" />
    <a-card :bordered="false">
      <b-table
        ref="table"
        :selectConfig="{use: true, type: 'radio',rowKey: 'id' }"
        :scroll="{x:1376}"
        :columns="columns"
        :request="loadData"
        @row-click="rowClick"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
      </b-table>
    </a-card>
  </a-modal>
</template>

<script>
import { signList } from '@/api/material/procurement/sign'
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'
import { selectOption } from '@/api/material/goods/goods'

export default {
  name: 'a' + Date.now(),
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      queryParam: {},
      statistics: {}, // 统计参数
      searchArr: [
        // 搜索框
        {
          name: '所属分公司',
          valueKey: 'branchCompanyId',
          type: SelectSubCompany
        },
        // {
        //   name: '项目名称',
        //   type: SelectProject,
        //   valueKey: 'projectId'
        // },
        {
          name: '招标评审会签编码',
          value: 'countersignCode',
          type: 'input'
        },
        {
          name: '招标文件评审编码',
          value: 'fileCode',
          type: 'input'
        },
        {
          name: '工程名称',
          value: 'wbsId',
          type: 'select',
          data: [],
          request: () => selectOption({ type: 18 })
        },
        {
          name: '开标地点',
          value: 'bidOpenAddr',
          type: 'input'
        },
        {
          name: '开标日期',
          value: 'bidOpenDate',
          type: 'dateRange'
        },
        {
          name: '创建人',
          value: 'creatorName',
          type: 'input'
        },
        {
          name: '创建时间',
          value: 'createTime',
          type: 'timeRangeFormat'
        }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          scopedSlots: { customRender: 'index' },
          width: 70
        }, {
          title: '所属分公司',
          dataIndex: 'branchCompanyName',
          width: 150
        },
        {
          title: '项目名称',
          dataIndex: 'projectNameByAuth',
          width: 150
        },
        {
          title: '物资招标评审会签编码',
          dataIndex: 'countersignCode',
          width: 180
        },
        {
          title: '物资招标文件评审编码',
          dataIndex: 'fileReviewCode',
          width: 180
        },
        {
          title: '工程名称',
          dataIndex: 'wbsName',
          width: 120
        },
        {
          title: '开标地点',
          dataIndex: 'bidOpenAddr',
          width: 120
        },
        {
          title: '开标日期',
          dataIndex: 'bidOpenDate',
          width: 120
        },
        {
          title: '创建人',
          dataIndex: 'creatorName',
          width: 160
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          width: 160
        },
        {
          title: '状态',
          width: this.STATUS_WIDTH,
          dataIndex: 'auditStatusStr',
          scopedSlots: { customRender: 'auditStatusStr' }
        }
      ],
      loadData: q => {
        let p = Object.assign(q, this.queryParam)
        p.auditStatus = 'PAST'
        return signList(p)
      },
      selectRow: null
    }
  },
  methods: {
    search(val = {}) {
      this.queryParam = val
      this.$refs.table.refresh()
    },
    rowClick(e, row) {
      this.selectRow = row
    },
    ok() {
      if (!this.selectRow) {
        return this.$noticeWarning('请选择数据')
      }
      this.$emit('ok', this.selectRow)
      this.cancel()
    },
    cancel() {
      this.$emit('update:visible', false)
    }
  }
}
</script>
